﻿using Abp.Application.Services;
using Logistics.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;


using AutoMapper;                         
using Volo.Abp.Application.Services;
using ApplicationService = Volo.Abp.Application.Services.ApplicationService;

namespace Logistics.Car
{
    public class FieIdAppService : ApplicationService, IFieIdAppService
    {
        private readonly IRepository<Field, int> _FieIdRepository;
        private readonly IFieIdRepository _IFieIdRepository;
        public FieIdAppService(IRepository<Field, int> FieIdRepository, IFieIdRepository IFieIdRepository)
        {

            _FieIdRepository = FieIdRepository;
            _IFieIdRepository = IFieIdRepository;
        }
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>

        public async Task<FieIdDto> Create(FieIdDto m)
        {
            var FieId = new Field
            {
                Name=m.Name,
                Fphone=m.Fphone,
                Femal=m.Femal,
                Fsite=m.Fsite,
                Ffixed=m.Ffixed,
                Fremark=m.Fremark,
                Fdate=m.Fdate
            };

            await _IFieIdRepository.Create(FieId);
            return ObjectMapper.Map<Field, FieIdDto>(FieId);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>

        public async Task DeleteAsync(int id)
        {
            await _IFieIdRepository.Delete(id);
            
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>

        public async Task<FieIdDto> GetCarryById(int Id)
        {
            var student = await _IFieIdRepository.GetCarryById(Id);
            return ObjectMapper.Map<Field, FieIdDto>(student);
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<PagedResultDto<FieIdDto>> GetListAsync(GetFieIdDto dto)
        {
            var vehiclelist = await _FieIdRepository.GetPagedListAsync(
               dto.SkipCount,
               dto.MaxResultCount,
               dto.Sorting);
            var totalCount = await AsyncExecuter.CountAsync(
               _FieIdRepository.WhereIf(
                   !dto.Filter.IsNullOrWhiteSpace(),
                   m => m.Name.Contains(dto.Filter)
               )
           );
            return new PagedResultDto<FieIdDto>(
             totalCount,
             ObjectMapper.Map<List<Field>, List<FieIdDto>>(vehiclelist));
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="ca"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>

        public async Task<int> Update(FieIdDto ca)
        {
            var carr = await _FieIdRepository.GetAsync(ca.Id);
            carr.Name = ca.Name;
            carr.Fphone = ca.Fphone;
            carr.Femal = ca.Femal;
            carr.Fsite = ca.Fsite;
            carr.Ffixed = ca.Ffixed;
            carr.Fremark = ca.Fremark;
            carr.Fdate = ca.Fdate;

            await _FieIdRepository.UpdateAsync(carr); 
            return 1;
        }
    }
}
